#include <stdlib.h>
#include <string.h>

#include <directfb.h>

#include "dtk_single_layout.h"
#include "dtk_debug.h"

const DString DTK_LAYOUT_TYPE_SINGLE = "DTKLayoutSingle";

static void single_measure (DTKLayout* layout, DSize* size)
{
    return;
}

static void single_release (DTKLayout* layout)
{
    if (layout == NULL)
    {
        return;
    }
    dtk_layout_remove_sub_all(layout->list);
    return;
}

static void single_add (DTKLayout* self, DTKLayout* layout)
{
    DInt count;

    count = dtk_list_get_count(&self->list);

    if (count > 0)
    {
        dtk_layout_remove_sub_all(self);
    }

    dtk_list_prepend(&self->list, &layout->link);

    layout->parent = self;

    return;
}

static void single_remove (DTKLayout* self, DTKLayout* layout)
{
    dtk_list_remove (&self->list, &layout->link);
    return;
}

void single_update (DTKLayout* layout)
{
    return;
}

DTKLayout* dtk_single_layout_new(DTKActor* actor)
{
    DTKLayout* layout;
    DTKLayoutSingle* absolute;

    layout = dtk_layout_new (sizeof(DTKLayoutSingle),
        DTK_LAYOUT_TYPE_SINGLE, actor);

    layout->update = single_update;

    layout->add = single_add;
    layout->remove = single_remove;

    layout->release = single_release;

    return layout;    
}

